#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
inline int read(){
    int res=0,f=1; char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        res=(res<<3)+(res<<1)+(ch^'0');
        ch=getchar();
    }
    return res*f;
}
int T,n,a[N*2+5],f[2*N+5];
long long ans=0;
void dfs(int dep,int la0,int la1,long long summ){
    if(dep>n){
        ans=max(summ,ans);
        return ;
    }
    if(a[dep+1]==a[la0]) dfs(dep+1,dep+1,la1,summ+a[la0]);
    else dfs(dep+1,dep+1,la1,summ);
    if(a[dep+1]==a[la1]) dfs(dep+1,la0,dep+1,summ+a[la1]);
    else dfs(dep+1,la0,dep+1,summ);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T){
        --T;n=read();ans=0;a[0]=1e4;
        for(int i=1;i<=n;++i) a[i]=read();
        dfs(0,0,0,0);
        printf("%lld\n",ans);
    }
    return 0;
}